const textToVoiceFn = function() {
    let retu = {
        support: false,
        addTextMag: function(str) {},
        msgInstance: null
    };
    if ('speechSynthesis' in window && 'SpeechSynthesisUtterance' in window) {
        retu.support = true;
        retu.msgInstance = new SpeechSynthesisUtterance();
    }
    retu.addTextMag = function(text) {
        if (retu.support && retu.msgInstance) {
            retu.msgInstance.text = text;
        };
        return this;
    }
    retu.speak = function() {
        if (!retu.support) return false;
        window.speechSynthesis.speak(retu.msgInstance);
    }
    return retu;
}

if (textToVoiceFn().support) {
    textToVoiceFn().addTextMag('hello').speak();
}